define(function(require, exports, module) {
	'use strict';
    
    var rk = require('rk');
    require('../../su/xsySuRefer/widget');

    var haveInit = false;

    $.widget('rk.xsyRescenterRefer', $.rk.xsySuRefer, {
        options: {
            iconClass: 'xsy_su_refer_rescenter_icon'
        },
        _create: function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;

            me._super();

            me.reload();
        },

        reload : function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;

             var config = {
                iconClass: opt.iconClass,
                title: '文档',
                amount: 19,
                buttons: ['upload'],
                children: [
                    {   
                        type: 'card'
                    }
                ],
                showEntityMenu : false,
                linkOfMore : '/doc.action?groupId=' + me._getGroupId() + "&fromBelongId=" + me._getCommonData().belongId + "&fromDataId=" + me._getDetailId(),
                linkOfFinal : '/final/file.action?fid={{id}}',
                childrenConfig:{
                    showMenu : false 
                }
            };

            var data = {groupId:me._getGroupId()};
            me._loadData(data, function (result){
                if(!haveInit){
                    me._render(config, result);
                    me._eventProcess();
                    haveInit = true;
                }else{
                    me._render(config, result);
                }
            });
        },
        _init:function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;
        },

        _eventProcess : function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;

            elem.crmFileUpload({
                groupId:me._getGroupId(),
                directoryId:-1,
                permission:function(){
                    return [1,3,2];
                },
                selector:'a.xsy_su_refer_upload',
                url:function(){
                    return "/json/sns_twitter_file/new-save-files.action";
                },
                fullPath : function(){
                    return "根目录";
                },
                success:function(){
                    me.reload();
                    me._triggerOuterEvent('referDataUpdated');
                },
                error: function () {
                    rk.noticeError(rk.i18n('TWITTERFILE_DIRECTORY_UPDATE_FAILURE'));
                }
            })

            me._listenInnerEvent('onReferCreateClick', function(info){
                //上传按钮，本应该在这里监听新建事件，但是为了用之前的上传控件rk.crmFileUpload，所以这里没有按照正常的流程中
            });
        }

    });
});